package com.java3_3;

import java.util.concurrent.locks.ReentrantLock;

public class Demo3 {
    private String name;
    private int age;

    private Demo3(String name, int age) {
        this.name = name;
        this.age = age;
    }

    private static Demo3 demo3 = null;
    private static final ReentrantLock reentrantLock = new ReentrantLock();

    public static Demo3 getDemo3() {
        try {
            reentrantLock.lock();
            if(demo3 == null){
                demo3 = new Demo3("zhangsan", 20);
            }
        } finally {
            reentrantLock.unlock();
        }
        return demo3;
    }

    @Override
    public String toString() {
        return "Demo3{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
